<?php
class Curls
{
    public static function post($url,$data)
    {
       
        $post_data = "";
        foreach($data as $k=>$v)
        {
            if($post_data == "")
            {
                $post_data = "$k=".urlencode($v);
            }
            else
            {
                $post_data .= "&$k=".urlencode($v);
            }
        }
        
        if(function_exists('file_get_contents'))
        {
            //$context['http']['header'] = 'Content-type: application/x-www-form-urlencoded'; 上传文件
            $context = array();
            $context['http'] = array(
                'method' => 'POST',
                'content' => $post_data,
            );   
            $result = @file_get_contents($url, false, stream_context_create($context)); 
        }
        else
        {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            //ssl
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept-language: zh-CN'));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
            $result = curl_exec($ch);
            curl_close($ch);
        }        
        return $result;
    }

    public static function get($url)
    {
        if(function_exists('file_get_contents'))
        {
            $result = @file_get_contents($url); 
        }
        else
        {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            //ssl
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept-language: zh-CN'));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $result = curl_exec($ch);
            curl_close($ch);
        }
        return $result;
    }
}
